using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;

namespace XMIAddin.Xmi
{
    public class UmlOwner : UmlVisibleModelElement
    {
        [XmlArray("Namespace.ownedElement", Namespace = "org.omg.xmi.namespace.UML"),
         XmlArrayItem(typeof(UmlPackage), ElementName = "Package", Namespace = "org.omg.xmi.namespace.UML"),
         XmlArrayItem(typeof(UmlDataType), ElementName="DataType", Namespace="org.omg.xmi.namespace.UML"),
         XmlArrayItem(typeof(UmlInterface), ElementName = "Interface", Namespace = "org.omg.xmi.namespace.UML"),
         XmlArrayItem(typeof(UmlClassifier), ElementName = "Class", Namespace = "org.omg.xmi.namespace.UML"),
         XmlArrayItem(typeof(UmlStereotype), ElementName = "Stereotype", Namespace = "org.omg.xmi.namespace.UML"),
         XmlArrayItem(typeof(UmlGeneralization), ElementName = "Generalization", Namespace = "org.omg.xmi.namespace.UML"),
         XmlArrayItem(typeof(UmlAbstraction), ElementName = "Abstraction", Namespace = "org.omg.xmi.namespace.UML")]
        public List<UmlModelElement> OwnedElements = new List<UmlModelElement>();

        private Dictionary<string, UmlModelElement> _Elements = new Dictionary<string, UmlModelElement>();

        public void Add(UmlModelElement element)
        {
            if (element.Name != null)
                _Elements.Add(element.Name, element);
            else
                _Elements.Add(element.Id.ToString(), element);

            OwnedElements.Add(element);
        }

        public UmlModelElement Fetch(string name)
        {
            if (_Elements.ContainsKey(name)) return _Elements[name];
            return null;
        }
    }
}
